<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户管理</title>

<link rel="stylesheet"
	href="assets/bootstrap-table/bootstrap-table.css">
<link rel="stylesheet"
	href="assets/bootstrap-table/bootstrap-editable.css">
<script src="assets/bootstrap-table/jquery.min.js"></script>
<script src="assets/bootstrap-table/bootstrap.min.js"></script>
<script src="assets/bootstrap-table/bootstrap-table.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-export.js"></script>
<script src="assets/bootstrap-table/tableExport.js"></script>
<script src="assets/bootstrap-table/bootstrap-table-editable.js"></script>
<script src="assets/bootstrap-table/bootstrap-editable.js"></script>
<script src="js/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>

<link rel="stylesheet" type="text/css" href="date/css/pikaday.css"/>
<script type="text/javascript" src="date/js/pikaday.min.js"></script>

<link rel='stylesheet' type='text/css' href='css/templetcss/other.css'>

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/json2/20140204/json2.min.js"></script>
<![endif]-->
<style>
.ml10 {
	margin-left: 10px;
}

#operate-success {

	font-size: 16px;
	background-color: #8AC007;
	color: #FBFBFB;
	visibility: hidden;
}
</style>
</head>
<body>
	<div style=" margin-left:15px">
		<div class="page-header">
			<h1>商品管理&nbsp;&nbsp;</h1>
		</div>
		<div id="QRimg"></div>
		<div style="text-align: center;">
			<span id="operate-success">设置成功</span>
		</div>



		<div id="toolbar" class="btn-group">
					<button id="plus" type="button" class="btn btn-default" title="新建商品">
						<i class="glyphicon glyphicon-plus" ></i>
					</button>
					<button id="edit" type="button" class="btn btn-default" title="编辑商品">
						<i class="glyphicon glyphicon-edit" ></i>
					</button>
					<button id="delete" type="button" class="btn btn-default" title="删除商品">
						<i class="glyphicon glyphicon-minus" ></i>
					</button>
					<button id="addFoodCountBtn" type="button" class="btn btn-default">
						添加库存
					</button>
                    <button class="btn btn-default dropdown-toggle " type="button" data-toggle="dropdown">
                                                                     选择日期<span class="caret"></span>
                      <ul class="dropdown-menu " role="menu" aria-labelledby="dropdownMenu1" >
                       <li role="presentation"><a role="menuitem" id="today" tabindex="-1" href="#">今天</a></li>
                       <li role="presentation"><a role="menuitem" id="week" tabindex="-1" href="#">一周内</a></li>
                       <li role="presentation"><a role="menuitem" id="month" tabindex="-1" href="#">一月内</a></li>
                     </ul>
                   </button>
				   <button type="button" class="btn btn-default ">
				      <input type="text" id="datepicker" style="width:90px;padding:0 5px 0 5px" placeholder="开始日期">
				      <i id="removestart" class="glyphicon glyphicon-remove"></i>
				   </button>
				   <button type="button" class="btn btn-default">
				      <input type="text" id="datepicker2" style="width:90px;padding:0 5px 0 5px" placeholder="结束日期">
				      <i id="revoveend" class="glyphicon glyphicon-remove"></i>
				   </button>
				   <button id="query" type="button" class="btn btn-default">
						查询
					</button>	
					 <button id="QRCode" type="button" class="btn btn-default">
					 <img src="img/QR.jpg" width="17px" height="17px">
						二维码
					</button>			 
			</div>
            
		    <div id="maintable">
			      <table id="table" data-id-field="foodId" data-striped="true"
					data-toolbar="#toolbar"
					data-search="true" data-show-refresh="true" data-show-toggle="true"
					data-pagination="true" data-show-columns="true" data-height="80%"
					data-click-to-select="true">
					<thead>
						<tr>
							<th data-field="state" data-checkbox="true"></th>
							<th data-align="left" data-field="foodId" data-sortable="true">ID</th>
							<th data-align="left" data-field="campusName" data-sortable="true">公众号名称</th>
							<th data-align="left" data-field="campusAdmin" data-sortable="true">商家</th>
							<th data-align="left" data-field="imgUrl" data-formatter="actionImg">商品图片</th>
							<th data-align="left" data-field="name">名&nbsp;&nbsp;&nbsp;&nbsp;称</th>
							<th data-align="left" data-field="message">商品介绍</th>							
							<th data-align="left" data-field="foodFlag" data-visible="false" >商品标签</th>							
							<th data-align="left" data-field="price" data-sortable="true">价格</th>
							<th data-align="left" data-field="primeCost" data-sortable="true">成本价</th>
							<th data-align="left" data-field="foodAllCount" data-sortable="true">总数</th>
							<th data-align="left" data-field="foodCount" data-sortable="true">库存</th>	
							 <th data-align="left" data-field="start" data-formatter="actionStatus">状态</th>	
							<th data-align="left" data-field="startTime2" data-sortable="true">开始时间</th>
							<th data-align="left" data-field="endTime2" data-sortable="true">结束时间</th>
							<th data-align="left" data-field="modifyTime2" data-visible="false" data-sortable="true">修改时间</th>											
							<th data-align="left" data-field="status" data-sortable="true" data-formatter="statusFormatter">审核情况</th>
                            <th data-align="left" data-field="audit" data-formatter="actionAudit">审核</th>
							<th data-align="left" data-field="categoryId" data-visible="false" data-sortable="true">所属分类</th>
							<th data-align="left" data-field="homeImageManage" data-formatter="actionDetail">详情</th>
						</tr>
					</thead>
				</table>
		</div>
	</div>
	
 <!-- 警告对话框 -->	
	<div class="modal fade" id="alertdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog">
          <div class="modal-content">
              <div class="modal-header blue">
                   <div >
                    	<strong id="alertchar" style="font-size:20px"></strong>
                   </div>
        
                   <div class="modal-footer">
			           <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
			           <button type="button" id="commitFoodDataButton" class="btn btn-primary">确定</button>
	               </div> 
              </div>
         </div>
       </div>
   </div>
	
	<!-- 添加库存modal start -->
	<div class="modal fade" id="addFoodCountModal" tabindex="-1" role="dialog" aria-labelledby="addFoodCountModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
					</button>
					<h4 class="modal-title" id="addFoodCountModalLabel">添加库存</h4>
				</div>
				<form class="form-horizontal" role="form">
					<div class="modal-body">
						<div class="form-group none">
							<label for="campus_id_add_count" class="control-label col-md-4">校区ID</label>
							<div class="col-md-8">
								<input type="text" class="form-control" id="campus_id_add_count" name="campusId" readonly>
							</div>
						</div>
						<div class="form-group">
							<label for="count_add_count" class="control-label col-md-2">商品库存</label>
							<div class="col-md-10">
								<input type="number" class="form-control" id="count_add_count" name="addCount">
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button" class="btn btn-primary" id="addFoodCountSubmit">提交更改</button>
					</div>
					<script type="text/javascript">
					 $("#addFoodCountSubmit").on("click",function(){
						var array = $("#table").bootstrapTable('getSelections');
						var foodCount1=array[0].foodCount;
						var foodCount=$("#count_add_count").val();
						var foodId=array[0].foodId;
						if(foodCount<1){
							alert("添加库存不能为0");
							return;
						}
						$.post("service/addFoodCountById.do", {
			                 foodId:foodId,
			                 foodCount:foodCount
						}, function(text) {
							if (text == -1 || text == 0) {
								$("#addFoodCountModal").modal('hide');
								setSuccess("失败。");
							} else {
								$("#addFoodCountModal").modal('hide');
								setSuccess("成功。");
								
								var url="service/getAllFoods.do?datepicker=null&datepicker2=null";

						    	$(" #table").bootstrapTable('refresh',{
									url : url
								});
							}
						});
						
					 });
					</script>
				</form>
				
			</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	<!-- 添加库存modal end -->
	
	<!-- 添加商品Modal start -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true">&times;</button>
					<h3 class="modal-title" id="myModalLabel">添加商品</h3>
				</div>
				<form id="dataCommit" class="form-horizontal" method="post"
					enctype="multipart/form-data" action="service/updateFoods.do">
					<div class="modal-body">
						<div class="form-group" style="display:none">
							<label class="control-label col-md-4" for="campusId2">公众号Id</label>
							<div class="input-group  col-md-5">
								<input type="text" id="campusId2" name="campusId" readonly="readonly">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="categoryId2">商品分类</label>
							<div class="input-group  col-md-5">
							   <select class="form-control" style="width:47%;padding:4px" id="categoryId2" name="parentId"
								class="selectpicker">
								</select>
							</div>							
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="campusAdmin2">选择商家</label>
							<div class="input-group  col-md-5">
							   <select class="form-control" style="width:47%;padding:4px" id="campusAdmin2" name="campusAdmin"
								class="selectpicker">
								</select>
							</div>							
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="foodName2">商品名称</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="foodName2" name="foodName"
									placeholder="名称">
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="message">商品介绍</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="message" name="message"
									placeholder="介绍">
							</div>
						</div>
						
						      <div class="form-group">
                           <label class="control-label col-md-4" for="startTime">开始时间</label>
                            <div class="input-group date form_datetime col-md-5" data-date-format="yyyy-mm-dd hh:ii:ss" data-link-field="dtp_input1">
                               <input class="form-control"  type="text" value="" readonly id="startTime2" name="startTime"
                               placeholder="开始(日期)">
                               <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				           	<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                         </div>
                        </div>
                        
                        
                        <div class="form-group">
                           <label class="control-label col-md-4" for="endTime">结束时间</label>
                            <div class="input-group date form_datetime col-md-5" data-date-format="yyyy-mm-dd hh:ii:ss" data-link-field="dtp_input1">
                               <input class="form-control"  type="text" value="" readonly  id="endTime2" name="endTime"
                               placeholder="结束(日期)">
                               <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
				           	<span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                         </div>
                        </div>
						
						<div class="form-group">
							<label class="control-label col-md-4" for="price2">商品价格</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="price2" name="price"
									placeholder="价格"> <span class="input-group-addon">￥</span>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4" for="primeCost2">成本价</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="primeCost2" name="primeCost"
									placeholder="成本价"> <span class="input-group-addon">￥</span>
							</div>
						</div>
						
			           <div class="form-group">
							<label class="control-label col-md-4" for="foodCount">商品库存</label>
							<div class="input-group col-md-5">
								<input  class="form-control" type="text" id="foodCount2" name="foodCount"
									placeholder="库存">
							</div>
						</div>	
						

						<div class="form-group">
							<label class="control-label col-md-4" for="imgUrl2">图片URL地址</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text"  id="imgUrl2" name="imgUrl"
									placeholder="请输入商品图片的链接">
							</div>
						</div>


						<div class="form-group">
							<label class="control-label col-md-4" for="foodTag2">商品标签</label>
							<div class="input-group  col-md-5">
								<input class="form-control" type="text" id="foodTag2" name="foodTag"
									placeholder="商品标签之间请以逗号隔开">
							</div>
						</div>

 						
 						<div class="form-group">
							<label class="control-label col-md-4" for="status">是否满减</label>
							<div class="col-md-8">
								<label class="radio inline"> <input type="radio"
									name="isFullDiscount" id="isFullDiscount" value="1" checked> 是
								</label> <label class="radio inline margin-left6"> <input type="radio"
									name="isFullDiscount" id="isFullDiscount" value="0"> 否
								</label>
							</div>
						</div>
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						<button type="button"
							class="btn btn-primary" onclick="commitFoodDataButton();">提交更改</button>
					</div>

					<input type="file" name="myfile" style="display:none">
                    <input input class="form-control" type="text" id="foodId2" name="foodId" style="display:none">
				</form>
				<script type="text/javascript">
				$("#table").bootstrapTable({
					url : "service/getAllFoods.do?datepicker=null&datepicker2=null"
				});
				
				 var picker = new Pikaday(
				 		    {
				 		        field: document.getElementById('datepicker')
				 		    });
				     var picker2 = new Pikaday(
				    		    {
				    		        field: document.getElementById('datepicker2')
				    		    });
				    
				    $("#removestart").on("click",function(){
				    	$("#datepicker").val("");
				    });

				    $("#revoveend").on("click",function(){
				    	$("#datepicker2").val("");
				    });
				    
				    
				    
				    $("#query").on("click",function(){
				    	var datepicker=$("#datepicker").val();
				    	var datepicker2=$("#datepicker2").val();
				    	var url="service/getAllFoods.do?datepicker="+datepicker+"&datepicker2="+datepicker2;
                        console.log("url="+url);
				    	$(" #table").bootstrapTable('refresh',{
							url : url
						});

				    });
				    
				    $("#QRCode").on("click",function(){
				    	$.post("QRCode/getUrl.do",{
				    		
				    	  },function(data){
				    		var QRimg="<img src="+data+">";
				    		if($("#QRimg").html()==''){
				    		  $("#QRimg").html(QRimg);
				    		 }else{
				    			$("#QRimg").empty();
				    		 }
				    	  });
				    });
				    
				    $("#today").on("click",function(){
				    	var Today=new Date();
				    	
				    	var datepicker=Today.getFullYear()+"-"+(Today.getMonth()+1)+"-"+Today.getDate()
				    	
				    	$("#datepicker").val(datepicker);
				    	$("#datepicker2").val(datepicker);
				    	var url="service/getAllFoods.do?datepicker="+datepicker+"&datepicker2="+datepicker;
				    	$(" #table").bootstrapTable('refresh',{
							url : url
						});
				    });
				
				    $("#week").on("click",function(){
				    	var Week=new Date();
				    	
				    	var datepicker=Week.getFullYear()+"-"+(Week.getMonth()+1)+"-"+(Week.getDate()-7);
				    	var datepicker2=Week.getFullYear()+"-"+(Week.getMonth()+1)+"-"+(Week.getDate());
				    	
				    	$("#datepicker").val(datepicker);
				    	$("#datepicker2").val(datepicker2);
				    	var url="service/getAllFoods.do?datepicker="+datepicker+"&datepicker2="+datepicker2;
				    	$(" #table").bootstrapTable('refresh',{
							url : url
						});
				    	
				    });
				    
				    $("#month").on("click",function(){
				        var Month=new Date();
				       
				        var datepicker=Month.getFullYear()+"-"+(Month.getMonth())+"-"+(Month.getDate());
				    	var datepicker2=Month.getFullYear()+"-"+(Month.getMonth()+1)+"-"+(Month.getDate());
				    	
				    	$("#datepicker").val(datepicker);
				    	$("#datepicker2").val(datepicker2);
				    	var url="service/getAllFoods.do?datepicker="+datepicker+"&datepicker2="+datepicker2;
				    	$(" #table").bootstrapTable('refresh',{
							url : url
						});
				    	
				        
				    });
				    
				function commitFoodDataButton(){
				    //对表单的数据进行验证
				    var categoryId=$("#categoryId2").val();
				    var foodCount=$("#foodCount2").val();
				    var foodId=$("#foodId2").val();
				    var foodName=$("#foodName2").val();
				    var imgUrl=$("#imgUrl2").val();
				    var price=$("#price2").val();
				    var primeCost=$("#primeCost2").val();
				    var startTime=$("#startTime2").val();
				    var endTime=$("#endTime2").val();
				    var $foodCommitDataForm=document.getElementById("dataCommit");
				    

				    console.log(categoryId);
				    if(!(/^[0-9]+$/.test(categoryId))){
				    	alert("上级分类id只可以是数字");
				    	return;
				    }

				    if(foodName==null||foodName==""){
				    	alert("商品名称不能为空!");
				    	return;
				    }
				    
				    if(!(/^\d+(\.\d{1,2})?$/).test(price)){
				    	alert("商品单价格式有问题,检查后重新输入。");
				    	return;
				    }


				    if(primeCost!=null&&primeCost!=""&&!(/^\d+(\.\d{1,2})?$/).test(primeCost)){
				    	alert("商品成本价输入格式有问题,检查后重新输入。");
				    	return;
				    }

				    if(imgUrl!=""){
				    	var re=/^((http|https|ftp):\/\/)?(\w(\:\w)?@)?([0-9a-z_-]+\.)*?([a-z0-9-]+\.[a-z]{2,6}(\.[a-z]{2})?(\:[0-9]{2,6})?)((\/[^?#<>\/\\*":]*)+(\?[^#]*)?(#.*)?)?$/i;  

				    	if(re.test(imgUrl)==false){
				    		alert("请输入正确的URL地址。");
					    	return;
				    	}
				    	
				    }

				    if(!(/^[0-9]*$/.test(foodCount))){
				    	alert("商品库存格式有问题,检查后重新输入。");
				    	return;
				    }

				    if(foodCount!=null&&foodCount!=""&&!(/\d+$/.test(foodCount))){
				    	alert("商品数量格式有问题，请检查后重新输入");
				    	return;
				    }

				    
				    if(startTime==""){
				    	alert("开始日期不能空");
				    	return;
				    }
				    
				    if(endTime==""){
				    	alert("结束日期不能空");
				    	return;
				    }
				    
				   $foodCommitDataForm.submit();
				}
				
				var date = new Date();
				Y = date.getFullYear() + '-';
				M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
				D = date.getDate() + ' ';
				h = date.getHours() + ':';
				m = date.getMinutes() + ':';
				s = date.getSeconds(); 
				console.log(Y+M+D+h+m+s)  

				    $('.form_datetime').datetimepicker({
				        //language:  'fr',
				        weekStart: 1,
				        todayBtn:  1,
						autoclose: 1,
						todayHighlight: 1,
						startView: 2,
						forceParse: 0,
				        showMeridian: 1
				    });
					$('.form_date').datetimepicker({
				        language:  'fr',
				        weekStart: 1,
				        todayBtn:  1,
						autoclose: 1,
						todayHighlight: 1,
						startView: 2,
						minView: 2,
						forceParse: 0
				    });
					$('.form_time').datetimepicker({
				        language:  'fr',
				        weekStart: 1,
				        todayBtn:  1,
						autoclose: 1,
						todayHighlight: 1,
						startView: 1,
						minView: 0,
						maxView: 1,
						forceParse: 0
				    });
				</script>
			</div>
			<!-- /.modal-content -->
		</div>
	</div>
	<!-- /.modal -->
	<!-- 添加商品Modal End -->
	
	
</body>

<script type="text/javascript">

var $table = $("#table");
var $addFoodCountBtn = $("#addFoodCountBtn");
var obj = document.getElementById("categoryId2");
var obj2 = document.getElementById("campusAdmin2");

$addFoodCountBtn.click(function(){
	var array = $("#table").bootstrapTable('getSelections');
	if(array.length==0){
		$('#alertchar').text('请至少选中一条记录！');
		$('#commitFoodDataButton').hide();
		$('#alertdialog').modal("show");
	}else if(array.length>1){
		$('#alertchar').text('不能同时编辑多条记录！');
		$('#commitFoodDataButton').hide();
		$('#alertdialog').modal("show");
	}else if(array.length==1){
		//alert(array[0].foodCount);
		$("#campus_id_add_count").val(1);
		$("#addFoodCountModal").modal('show');
	}	

});




$('#plus').click(function() {
	$("#myModalLabel").text("添加商品");
	$("#myModal").modal('show');
	tag=0;
});

$("#myModal").on(
		"shown.bs.modal",
		function() {
			  
			$.get(
				"service/getAllFoodCategories4Client.do",
				function(text) {
					obj.options.length = 0;//清楚modal的数据
					var json = eval('(' + text
						+ ')');
					for ( var i = 0; i < json.length; i++) {
						obj.options
						.add(new Option(
							json[i].category,
							json[i].categoryId));
					}
				});
	});
	
$("#myModal").on(
		"shown.bs.modal",
		function() {
			  
			$.get(
				"seller/getCampusAdmin.do",
				function(text) {
					obj2.options.length = 0;//清楚modal的数据
					var json = eval('(' + text
						+ ')');
					for ( var i = 0; i < json.length; i++) {
						obj2.options
						.add(new Option(
							json[i].campusAdmin));
					}
				});
	});
 
 //js把时间戳转为为普通日期格式
 function getLocalTime(nS) {    
	 var date = new Date(nS);

	 Y = date.getFullYear() + '-';
	 M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
	 D = date.getDate() + ' ';
	 h = date.getHours() + ':';
	 m = date.getMinutes() + ':';
	 s = date.getSeconds(); 
	 
	 return (Y+M+D+h+m+s);  
	 
	}

 
$('#edit').on('click',function() {
			var array = $('#table').bootstrapTable('getSelections');
			tag=1;

			if (array.length > 1) {
				$('#alertchar').text('编辑操作不能同时选中多条记录！');
				$('#commitFoodDataButton').hide();
				$('#alertdialog').modal("show");
			} else if (array.length == 0) {
				$('#alertchar').text('请先选中某条记录！');
				$('#commitFoodDataButton').hide();
				$('#alertdialog').modal("show");
			} else {
				$("#myModalLabel").text("编辑商品");
				$("#myModal").modal('show');

				$("#foodId2").val(array[0].foodId);
				$("#foodId2").attr('readonly',true);
				$("#foodName2").val(array[0].name);
				$("#price2").val(array[0].price);
				$("#primeCost2").val(array[0].primeCost);
				$("#foodTag2").val(array[0].foodFlag);
				$("#imgUrl2").val(array[0].imgUrl);
				$("#categoryId2").val(array[0].categoryId);
				$("#foodCount2").val(array[0].foodCount);
                $("#message").val(array[0].message);
                $("#startTime2").val(getLocalTime(array[0].startTime));
                $("#endTime2").val(getLocalTime(array[0].endTime));
                
                /*
				var status=document.getElementsByName("status")
				status[1-array[0].status].checked=true;
                */
			}
		});


$('#delete').on('click',function() {
	var array = $('#table').bootstrapTable('getSelections'); //获取选中的所有记录
	var foodIdString = "";
	var deltext="";
	if (array.length == 0){

			$('#alertchar').text('请先选中要删除的记录！');
			$('#commitFoodDataButton').hide();
			$('#alertdialog').modal("show");

	}else {
		for ( var i = array.length - 1; i >= 0; i--) {
			if (i == 0) {
				foodIdString += array[i].foodId; //连接最末不加，号
				deltext+=array[i].name;
			} else {
				foodIdString += array[i].foodId + ","; //id用逗号连接
				deltext+=array[i].name+",";
			}
		}
        

		var foodtext='是否确定要删除 '+deltext+' ? ';
		
		$('#alertchar').text(foodtext);
		$('#commitFoodDataButton').show();
		$('#alertdialog').modal("show");
		
		$('#commitFoodDataButton').click(function(){
			//做删除的访问请求
			$.post("../../shambles/service/deleteFood.do", {
				foodId : foodIdString
			}, function(text) {
				var json = eval('(' + text + ')');
				if (json.status == "success") {				
					/*
					for ( var i = array.length - 1; i >= 0; i--) {
						$('#table').bootstrapTable('remove', {
							field : 'foodId',
							values : [ array[i].foodId ]
						});
					   }
						*/
						
						/*
						 * 刷新页面
						 */
						var url="service/getAllFoods.do?datepicker=null&datepicker2=null";

				    	$(" #table").bootstrapTable('refresh',{
							url : url
						});
				    	
					$('#alertchar').text(json.message);
					setTimeout(function(){
					 $('#alertdialog').modal("hide");
					},1000);
				} else {
					$('#alertchar').text(json.message);
					setTimeout(function(){
						 $('#alertdialog').modal("hide");
						},1000);
				}
			});
		});
	}

});


function actionStatus(value, row, index){
	if (value == "0"){
		return "<img src='img/start.jpg' width='15px' height='13px' title='未开始'></i>";
	}else if (value == "1") {
		return "<img src='img/go.jpg' width='15px' height='13px' title='进行中'></i>";
	}else if(value=="2"){
		return "<img src='img/end.jpg' width='13px' height='13px' title='已结束'></i>";
	}
}

function statusFormatter(value, row, index) {
	if (value == "0")
		return "<img src='img/wrong.jpg' width='15px' height='15px'></i>未审核";
	else if (value == "1") {
		return "<img src='img/right.jpg' width='15px' height='15px'></i>已审核";
	}
}

function actionAudit(value, row, index) {
	if (adminType == 0) {
		//当前角色是校区管理员
		return [
				'<a class="ml8" href="javascript:void(0)" onclick="agree(this);" title="通过审核">',
				'&nbsp;<i class="glyphicon glyphicon-ok"></i>&nbsp;',
				'</a>'].join('');
	} else if (adminType == 1) {
		//当前角色是总校区管理员
		return "无权操作";
	}
}

function actionImg(value, row, index) {
	return ['<div class="detail-image">',
			'&nbsp;<img src="'+value+'" height="33px">&nbsp;',
			'</div>'].join('');
}

function actionDetail(value, row, index) {
		return [
				'<a  href="javascript:void(0)" onclick="detail(this);" title="点击查看商品详情">',
				'&nbsp;<img src="img/detail.jpg" width="25px" height="25px">&nbsp;',
				'</a>'].join('');
}

function agree(temp) {
	var hang = $(temp.parentNode).parent().prevAll().length+1;  //jquery获取td所在的行和列
   //var lie = $(temp.parentNode).prevAll().length+1;  
   //alert("第"+hang+"行"+"	"+"第"+lie+"列"); 

	 var val=document.getElementById("table").rows[hang].cells[1]; //取得所在列的值
     var foodId=val.innerHTML; 

	       $.post("templet/getPurchaseTemplet.do",{      //生成模板
	    	       foodId:foodId
	       },function(text){
	    	   
	       });
	 
			$.post("service/updateStatus.do", {
                 foodId:foodId
			}, function(text) {
				if (text == -1 || text == 0) {
					setSuccess("审核失败。");
				} else {
					setSuccess("审核成功。");
					var url="service/getAllFoods.do?datepicker=null&datepicker2=null";

			    	$(" #table").bootstrapTable('refresh',{
						url : url
					});
				}

			});
		}

function detail(temp){
	var hang = $(temp.parentNode).parent().prevAll().length+1;  //jquery获取td所在的行和列
	   //var lie = $(temp.parentNode).prevAll().length+1;  
	   //alert("第"+hang+"行"+"	"+"第"+lie+"列"); 

		 var val=document.getElementById("table").rows[hang].cells[1]; //取得所在列的值
	     var foodId=val.innerHTML; 

		 
		   $('#content').load('pages/fooddetail.html');
		   $('#content').attr('src','pages/fooddetail.html');
		   $('#content').attr('foodId',foodId);
}

</script>
</html>